import { defineStore } from 'pinia'
import { ref } from 'vue'

export interface Photo {
  id: number
  title: string
  description?: string
  url: string
  date: string
}

export interface Album {
  id: number
  title: string
  cover: string
  description?: string
  date: string
  photos: Photo[]
}

export const useAlbumStore = defineStore('album', () => {
  // 示例数据，实际应用中可以从API获取
  const albums = ref<Album[]>([
    {
      id: 1,
      title: '春日花园',
      cover: 'https://images.unsplash.com/photo-1465146344425-f00d5f5c8f07',
      description: '春天里的花园风光',
      date: '2023-03-15',
      photos: [
        {
          id: 101,
          title: '盛开的樱花',
          url: 'https://images.unsplash.com/photo-1522383225653-ed111181a951',
          date: '2023-03-15'
        },
        {
          id: 102,
          title: '郁金香花海',
          url: 'https://images.unsplash.com/photo-1524593166156-312f362cada0',
          date: '2023-03-16'
        },
        // 可以添加更多照片
      ]
    },
    {
      id: 2,
      title: '夏日海滩',
      cover: 'https://images.unsplash.com/photo-1507525428034-b723cf961d3e',
      description: '夏天的海滩记忆',
      date: '2023-07-20',
      photos: [
        {
          id: 201,
          title: '日落海岸',
          url: 'https://images.unsplash.com/photo-1414609245224-afa02bfb3fda',
          date: '2023-07-20'
        },
        {
          id: 202,
          title: '蓝天白云',
          url: 'https://images.unsplash.com/photo-1437719417032-8595fd9e9dc6',
          date: '2023-07-21'
        },
        // 可以添加更多照片
      ]
    }
    // 可以添加更多相册
  ])

  // 获取所有相册
  const getAllAlbums = () => albums.value
  
  // 根据ID获取相册
  const getAlbumById = (id: number) => {
    return albums.value.find(album => album.id === id)
  }

  // 根据相册ID和照片ID获取照片
  const getPhotoById = (albumId: number, photoId: number) => {
    const album = getAlbumById(albumId)
    if (!album) return null
    return album.photos.find(photo => photo.id === photoId)
  }

  return { albums, getAllAlbums, getAlbumById, getPhotoById }
})